/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package tuneControllers;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import tuneModels.VolumeControl;
import tuneViews.Volume;

/**
 *
 * @author Israel Agyeman-Premp
 */
public class VolumeController {

    MouseListener mouseListener;
    MouseMotionListener mouseMotion;
    VolumeControl vc;
    Volume v;

    /**
     * Default constructor takes a volume control and volume class to connect
     * them together
     *
     * @param vc
     * @param v
     */
    public VolumeController(VolumeControl vc, Volume v) {
        this.vc = vc;
        this.v = v;
        v.setVisible(true);
    }

    /**
     * The control class of Volume control instantiates all the mouse and action
     * listeners.
     */
    public void control() {
        mouseListener = new MouseListener() {

            @Override
            public void mouseClicked(MouseEvent e) {
                if (e.getSource() == v.getClose()) {
                    v.dispose();
                } else if (e.getSource() == v.getSlider()) {
                    if (e.getSource() == v.getSlider()) {
                        currVolume = v.getSlider().getValue();
                        vc.alterVolume(currVolume);
                        v.getValue().setText(String.valueOf((int) currVolume));
                    }
                }
            }

            @Override
            public void mousePressed(MouseEvent e) {

            }

            @Override
            public void mouseReleased(MouseEvent e) {

            }

            @Override
            public void mouseEntered(MouseEvent e) {

            }

            @Override
            public void mouseExited(MouseEvent e) {

            }

            public void mouseMoved(MouseEvent e) {

            }
        };

        mouseMotion = new MouseMotionListener() {

            @Override
            public void mouseDragged(MouseEvent e) {
                if (e.getSource() == v.getSlider()) {
                    currVolume = v.getSlider().getValue();
                    vc.alterVolume(currVolume);
                    //vc.setGain(currVolume);
                    v.getValue().setText(String.valueOf((int) currVolume));
                }
            }

            @Override
            public void mouseMoved(MouseEvent e) {

            }
        };

        /**
         * Adding necessary action listeners and mouselisteners
         */
        v.getClose().addMouseListener(mouseListener);
        v.getSlider().addMouseListener(mouseListener);
        v.getSlider().addMouseMotionListener(mouseMotion);

    }

    /**
     *
     * A variable showing the current position of the volume
     */
    float currVolume = 50;

}
